window.onload = function () {
    //banner图轮播效果
    banner();
    function banner() {
        var ban = document.querySelector('.banner');
        var imgs = ban.querySelectorAll('img');
        var circle = document.querySelector('.circle');

        var myTimer = null;
        var index = 0;

        myTimer = setInterval(function () {
            if (index < imgs.length - 1) {
                index++;
            } else {
                index = 0;
            }
            move();
        }, 1500);

        for (var i = 0; i < imgs.length; i++) {
            circle.innerHTML += '<li></li>';
        }

        var cirLi = circle.querySelectorAll('li');
        cirLi[index].classList.add('color');
        for (var j = 0; j < cirLi.length; j++) {
            (function (j) {
                cirLi[j].onclick = function () {
                    index = j;
                    move();
                }
            })(j)
        }

        //鼠标悬浮停止
        ban.addEventListener('mouseover', function () {
            clearInterval(myTimer);
        })
        ban.addEventListener('mouseout', function () {
            myTimer = setInterval(function () {
                if (index < imgs.length - 1) {
                    index++;
                } else {
                    index = 0;
                }
                move();
            }, 1500);
        })
        function move() {
            for (var i = 0; i < imgs.length; i++) {
                imgs[i].classList.remove('active');
                cirLi[i].classList.remove('color');
            }
            imgs[index].classList.add('active');
            cirLi[index].classList.add('color');
        }
    }



    // tab 切换
    var btn = document.querySelectorAll('.tab ul li');
    var show = document.querySelectorAll('.swiper div');
    
    for (var i = 0; i < btn.length; i++) {
        btn[i].index = i;
        btn[i].onclick = function () {

            for (var j = 0; j < 2; j++) {
                show[j].style.display = 'none';
                btn[j].className = '';
            }
            show[this.index].style.display = 'block';
            btn[this.index].className = 'sactive'
        }
    }


    //点击上下图片
    var left = document.querySelector('.btn-left');
    var right = document.querySelector('.btn-right');
    var man = document.querySelector('.swiper .man');
    console.log(man);
    left.addEventListener('click',function(){
        man.style.left   = 200 + 'px';
        
    })


    right.addEventListener('click',function(){
        
    })




    // 返回顶部
    var stick = document.querySelector('.stick');
    stick.onclick = function(){
        console.log(123);
        window.scrollTo({
            top:0,
            left:0,
            behavior:"smooth"
        });
    }
}